package com.wx.reflection;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.util.Random;

/**
 * @program: my-java
 * @description: 反射测试类
 * @author: Wang.xun
 * @create: 2021-03-02 20:59
 **/
@Slf4j
public class TestRef01 {
    private String name;

    public TestRef01() {

    }

    public TestRef01(String name) {
        log.info(this.toString());
        this.name = name;
    }

    void eat(String food){
        int o = new Random().nextInt(988);
        log.info(food+o);
    }
    void eat(String food,int abc){
        int o = abc;
        log.info(food+o);
    }

    public static void main(String[] args) throws Exception{
        Class clazz = Class.forName("com.wx.reflection.TestRef01");
        Method eat = clazz.getDeclaredMethod("eat", String.class);
        Method eatInt = clazz.getDeclaredMethod("eat", String.class, Integer.TYPE);

        Object obj = clazz.newInstance();
        for (int i = 0; i < 20; i++) {
            eat.invoke(obj,"hahaha");
            eatInt.invoke(obj,"hehehe",123);
        }


    }
}
